package com.uy.system.mapper;

import com.uy.system.model.entity.SysRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.uy.system.model.vo.SysRoleVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 角色信息表 Mapper 接口
 * </p>
 *
 * @author ly
 * @since 2024-03-22
 */
public interface SysRoleMapper extends BaseMapper<SysRole> {

    /**
     * 获取用户角色信息
     * @param userId
     * @return
     */
    @Select("""
        SELECT sr.role_id AS roleId,sr.role_name AS roleName,sr.role_key AS roleKey,sur.user_id FROM sys_role sr
        JOIN sys_user_role sur ON sur.role_id = sr.role_id
        WHERE sr.status = 0 AND sr.del_flag = 0 AND sur.user_id = #{userId}
    """)
    SysRole getSysRoleByUserId(@Param("userId") Long userId);

    /**
     * 获取角色信息
     * @return
     */
    @Select("""
        SELECT role_id AS roleId,role_name AS roleName FROM sys_role
        WHERE status = 0 AND del_flag = 0
    """)
    List<SysRoleVO> getSysRoleList();

    /**
     * 获取用户角色信息
     * @param userId 用户id
     * @return
     */
    @Select("""
        SELECT sr.role_key AS roleKye FROM sys_role sr
        JOIN sys_user_role sur ON sr.role_id = sur.role_id
        WHERE sr.status = 0 AND sr.del_flag = 0 AND sur.user_id = 2
    """)
    List<String> getRoleList(@Param("userId") Long userId);
}
